{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "0374bf48-1ee4-49dd-9013-aaaeceb34a09",
   "metadata": {},
   "source": [
    "# Python科学数据处理"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "87e84fe2-d853-433c-9555-bbb54f6790ff",
   "metadata": {},
   "source": [
    "- 1 KB（Kilobyte） 表示 $1024$ 字节，即$2^{10}$ 字节；\n",
    "- 1 MB（Megabyte）表示 $1024*1024$字节，$2^{20}$ 字节；\n",
    "- 1 GB（Gigabyte）表示 $2^{30}$ 字节；\n",
    "- 1 TB（Terabyte） 表示 $2^{40}$ 字节；\n",
    "- 1 PB（Petabyte） 表示 $2^{50}$ 字节；\n",
    "- 1 EB（Exabyte） 表示 $2^{60}$ 字节；\n",
    "- 1 ZB（Zettabyte） 表示 $2^{70}$ 字节；\n",
    "- 1 YB（YottaByte） 表示 $2^{80}$ 字节；"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d83da18d-f2f8-473e-9bc6-9d1d13ef6a33",
   "metadata": {},
   "source": [
    "## 数据量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "4638fd0f-dee8-4c37-8693-fa63eafdf960",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "47185920.0\n"
     ]
    }
   ],
   "source": [
    "print ( (720*2**50)/(16*2**30) )"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dc0a73b6-ad54-4619-948e-c9586631097e",
   "metadata": {},
   "source": [
    "### 必记"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "36b25c96-c3fa-4ff9-83b3-a0892be3a4f8",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import numpy as np #科学计算核心库\n",
    "import pandas as pd #数据分析支持库\n",
    "import matplotlib.pyplot as plt  #画图基础\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "73c7d43e-ea2f-4294-8471-1b6758f657f4",
   "metadata": {},
   "outputs": [],
   "source": [
    "%%writefile velocity.csv  #写一个名为velocity的csv文件\n",
    "name,velocity,earth       #文件内容\n",
    "苹果,0.1,falldown\n",
    "网球,50,falldown\n",
    "羽毛球,63,falldown\n",
    "大炮,600,falldown\n",
    "子弹,850,falldown\n",
    "鬼怪,2370,falldown\n",
    "防空导弹,3000,falldown\n",
    "神7,7820,flyout\n",
    "新视野号,16260.0,flyout"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "ac09c119-dd49-4372-8d9c-857f98acbc5c",
   "metadata": {},
   "outputs": [
    {
     "ename": "FileNotFoundError",
     "evalue": "[Errno 2] No such file or directory: 'velocity_earth.csv'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mFileNotFoundError\u001b[0m                         Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[7], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m df \u001b[38;5;241m=\u001b[39m pd\u001b[38;5;241m.\u001b[39mread_csv(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mvelocity_earth.csv\u001b[39m\u001b[38;5;124m'\u001b[39m)   \u001b[38;5;66;03m#用pandas打开csv名为velocity_earth.csv的文件\u001b[39;00m\n\u001b[0;32m      2\u001b[0m df\n",
      "File \u001b[1;32mD:\\python\\Lib\\site-packages\\pandas\\io\\parsers\\readers.py:1026\u001b[0m, in \u001b[0;36mread_csv\u001b[1;34m(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, skipfooter, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, date_format, dayfirst, cache_dates, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, doublequote, escapechar, comment, encoding, encoding_errors, dialect, on_bad_lines, delim_whitespace, low_memory, memory_map, float_precision, storage_options, dtype_backend)\u001b[0m\n\u001b[0;32m   1013\u001b[0m kwds_defaults \u001b[38;5;241m=\u001b[39m _refine_defaults_read(\n\u001b[0;32m   1014\u001b[0m     dialect,\n\u001b[0;32m   1015\u001b[0m     delimiter,\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m   1022\u001b[0m     dtype_backend\u001b[38;5;241m=\u001b[39mdtype_backend,\n\u001b[0;32m   1023\u001b[0m )\n\u001b[0;32m   1024\u001b[0m kwds\u001b[38;5;241m.\u001b[39mupdate(kwds_defaults)\n\u001b[1;32m-> 1026\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m _read(filepath_or_buffer, kwds)\n",
      "File \u001b[1;32mD:\\python\\Lib\\site-packages\\pandas\\io\\parsers\\readers.py:620\u001b[0m, in \u001b[0;36m_read\u001b[1;34m(filepath_or_buffer, kwds)\u001b[0m\n\u001b[0;32m    617\u001b[0m _validate_names(kwds\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mnames\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;28;01mNone\u001b[39;00m))\n\u001b[0;32m    619\u001b[0m \u001b[38;5;66;03m# Create the parser.\u001b[39;00m\n\u001b[1;32m--> 620\u001b[0m parser \u001b[38;5;241m=\u001b[39m TextFileReader(filepath_or_buffer, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwds)\n\u001b[0;32m    622\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m chunksize \u001b[38;5;129;01mor\u001b[39;00m iterator:\n\u001b[0;32m    623\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m parser\n",
      "File \u001b[1;32mD:\\python\\Lib\\site-packages\\pandas\\io\\parsers\\readers.py:1620\u001b[0m, in \u001b[0;36mTextFileReader.__init__\u001b[1;34m(self, f, engine, **kwds)\u001b[0m\n\u001b[0;32m   1617\u001b[0m     \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39moptions[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mhas_index_names\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;241m=\u001b[39m kwds[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mhas_index_names\u001b[39m\u001b[38;5;124m\"\u001b[39m]\n\u001b[0;32m   1619\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mhandles: IOHandles \u001b[38;5;241m|\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[1;32m-> 1620\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_engine \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_make_engine(f, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mengine)\n",
      "File \u001b[1;32mD:\\python\\Lib\\site-packages\\pandas\\io\\parsers\\readers.py:1880\u001b[0m, in \u001b[0;36mTextFileReader._make_engine\u001b[1;34m(self, f, engine)\u001b[0m\n\u001b[0;32m   1878\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mb\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;129;01min\u001b[39;00m mode:\n\u001b[0;32m   1879\u001b[0m         mode \u001b[38;5;241m+\u001b[39m\u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mb\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m-> 1880\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mhandles \u001b[38;5;241m=\u001b[39m get_handle(\n\u001b[0;32m   1881\u001b[0m     f,\n\u001b[0;32m   1882\u001b[0m     mode,\n\u001b[0;32m   1883\u001b[0m     encoding\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39moptions\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mencoding\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;28;01mNone\u001b[39;00m),\n\u001b[0;32m   1884\u001b[0m     compression\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39moptions\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcompression\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;28;01mNone\u001b[39;00m),\n\u001b[0;32m   1885\u001b[0m     memory_map\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39moptions\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmemory_map\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;28;01mFalse\u001b[39;00m),\n\u001b[0;32m   1886\u001b[0m     is_text\u001b[38;5;241m=\u001b[39mis_text,\n\u001b[0;32m   1887\u001b[0m     errors\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39moptions\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mencoding_errors\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mstrict\u001b[39m\u001b[38;5;124m\"\u001b[39m),\n\u001b[0;32m   1888\u001b[0m     storage_options\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39moptions\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mstorage_options\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;28;01mNone\u001b[39;00m),\n\u001b[0;32m   1889\u001b[0m )\n\u001b[0;32m   1890\u001b[0m \u001b[38;5;28;01massert\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mhandles \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[0;32m   1891\u001b[0m f \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mhandles\u001b[38;5;241m.\u001b[39mhandle\n",
      "File \u001b[1;32mD:\\python\\Lib\\site-packages\\pandas\\io\\common.py:873\u001b[0m, in \u001b[0;36mget_handle\u001b[1;34m(path_or_buf, mode, encoding, compression, memory_map, is_text, errors, storage_options)\u001b[0m\n\u001b[0;32m    868\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(handle, \u001b[38;5;28mstr\u001b[39m):\n\u001b[0;32m    869\u001b[0m     \u001b[38;5;66;03m# Check whether the filename is to be opened in binary mode.\u001b[39;00m\n\u001b[0;32m    870\u001b[0m     \u001b[38;5;66;03m# Binary mode does not support 'encoding' and 'newline'.\u001b[39;00m\n\u001b[0;32m    871\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m ioargs\u001b[38;5;241m.\u001b[39mencoding \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mb\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;129;01min\u001b[39;00m ioargs\u001b[38;5;241m.\u001b[39mmode:\n\u001b[0;32m    872\u001b[0m         \u001b[38;5;66;03m# Encoding\u001b[39;00m\n\u001b[1;32m--> 873\u001b[0m         handle \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mopen\u001b[39m(\n\u001b[0;32m    874\u001b[0m             handle,\n\u001b[0;32m    875\u001b[0m             ioargs\u001b[38;5;241m.\u001b[39mmode,\n\u001b[0;32m    876\u001b[0m             encoding\u001b[38;5;241m=\u001b[39mioargs\u001b[38;5;241m.\u001b[39mencoding,\n\u001b[0;32m    877\u001b[0m             errors\u001b[38;5;241m=\u001b[39merrors,\n\u001b[0;32m    878\u001b[0m             newline\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[0;32m    879\u001b[0m         )\n\u001b[0;32m    880\u001b[0m     \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m    881\u001b[0m         \u001b[38;5;66;03m# Binary mode\u001b[39;00m\n\u001b[0;32m    882\u001b[0m         handle \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mopen\u001b[39m(handle, ioargs\u001b[38;5;241m.\u001b[39mmode)\n",
      "\u001b[1;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: 'velocity_earth.csv'"
     ]
    }
   ],
   "source": [
    "df = pd.read_csv('velocity_earth.csv')   #用pandas打开csv名为velocity_earth.csv的文件，把打开的东西交给df\n",
    "df                                       #把打开的东西交给df"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "edc8906d-c6b7-467c-8d33-3d31407204f1",
   "metadata": {},
   "source": [
    "- bar 柱状图\n",
    "- head 前面的\n",
    "- tail 后面的"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "10ca728a-4f1b-4d94-b3e0-e9c89c05b7db",
   "metadata": {},
   "outputs": [],
   "source": [
    "df['earth'].value_counts()   #数据计算"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "22ad32fe-a242-4de4-adc3-22fa31ef1aca",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'df' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[5], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m freqs \u001b[38;5;241m=\u001b[39m df[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mearth\u001b[39m\u001b[38;5;124m'\u001b[39m]\u001b[38;5;241m.\u001b[39mvalue_counts()             \u001b[38;5;66;03m#赋值\u001b[39;00m\n\u001b[0;32m      2\u001b[0m X \u001b[38;5;241m=\u001b[39m np\u001b[38;5;241m.\u001b[39marange(\u001b[38;5;28mlen\u001b[39m(freqs))\n\u001b[0;32m      3\u001b[0m plt\u001b[38;5;241m.\u001b[39mbar(X, freqs, tick_label\u001b[38;5;241m=\u001b[39mfreqs\u001b[38;5;241m.\u001b[39mindex)      \n",
      "\u001b[1;31mNameError\u001b[0m: name 'df' is not defined"
     ]
    }
   ],
   "source": [
    "freqs = df['earth'].value_counts()             #赋值\n",
    "X = np.arange(len(freqs))\n",
    "plt.bar(X, freqs, tick_label=freqs.index)      \n",
    "plt.title('fly out of earth')                  # 柱状图标题名称\n",
    "plt.xlabel('result')                           # x坐标轴的标签\n",
    "plt.ylabel('number')                           # y坐标轴的标签\n",
    "plt.show()                                     # 展现"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2c4dfef4-9740-4556-959b-3dd8fc192a8a",
   "metadata": {},
   "source": [
    "### 数据分析典型流程\n",
    "\n",
    "1. 确定目标：大致确定数据分析领域，以及问题分析报告的目标\n",
    "2. 数据收集：从各个数据来源收集整理数据（爬虫与购买）；\n",
    "3. 数据清洗：对收集的数据进行质量检查；对数据进行标识整理、把数据结构化。\n",
    "4. 数据探索：通过探索来熟悉数据，查看数据，通过绘图、拟合，特征量计算等来查看数据规律。\n",
    "5. 分析与建模：在探索分析基础上，提出可能的模型；通过分析来选定模型，进一步对选定模型进行测试验证。\n",
    "6. 模型评价与优化：评价模型优劣，对模型进行优化。\n",
    "7. 模型应用：在真实环境中，部署获得模型进行实际应用。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d1080b3d-4281-48d6-9ebb-fc24667f544a",
   "metadata": {},
   "source": [
    "# Numpy学习\n",
    "Numpy 是 Numerical Python的简称，是 Python 数值计算最重要的基础包。大多数科学计算工具包都会用 Numpy 的数组作为基础。Numpy 主要功能包括如下：\n",
    "- `ndarray`，具有矢量运算和复杂广播能力的多维数组。\n",
    "- 对多维数组进行快速计算的数学函数（ufunc）。\n",
    "- 读写硬盘数据以及操作内存映射文件的工具。\n",
    "- 线性代数、随机数以及傅里叶变换功能。\n",
    "- 用于集成C、C++、Fortran等语言编写代码的工具。\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "1239814f-a5e3-46d5-a2f7-dd0904e4d1d6",
   "metadata": {},
   "outputs": [],
   "source": [
    "import math\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ed03ed1e-8bcf-4718-86cb-f1cbba23701e",
   "metadata": {},
   "source": [
    "## python保存数据的方法\n",
    "- list 列表\n",
    "- dictionary 字典\n",
    "- set 集合\n",
    "- tuple 元组"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3b7b65ea-67f7-41ce-84c2-ed3d94ae0524",
   "metadata": {},
   "source": [
    "##### Numpy包提供：\n",
    "- `ndarray`，是`n-dimensional array object`的缩写，用来存储单一数据类型的多维数组（后续章节统称为数组）。\n",
    "- `ufunc`是`universal function object`的缩写，是一组对ndarray中的数据进行元素级运算的函数。\n",
    "- 实用函数\n",
    "- 常数"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f31963f3-5aa3-4d5f-b4f6-5a989781e5fe",
   "metadata": {},
   "source": [
    "#### 常数\n",
    "\n",
    "Numpy包提供由常用的数学常数：\n",
    "- `np.pi`: 圆周率$\\pi$\n",
    "- `np.e`: 自然对数$e$\n",
    "- `np.euler_gamma`: 欧拉常数\n",
    "- `np.PZERO, np.NZERO`: 正数零，负数零\n",
    "- `np.nan, np.NaN, np.NAN`: 非数字\n",
    "- `np.inf, np.Inf, np.Infinity, np.PINF, np.NINF, np.infty`: 无穷大"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "0405a355-b069-42d8-bbd1-7c3f9962002f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(3.141592653589793, 2.718281828459045, 0.5772156649015329, 0.0, -0.0)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.pi, np.e, np.euler_gamma, np.PZERO, np.NZERO"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "27c0a97d-d29d-4841-88c2-3f3689f59181",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(nan, nan, nan, inf, inf, inf, -inf, inf, inf)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.nan, np.NaN, np.NAN, np.inf, np.Inf, np.Infinity, np.NINF, np.PINF, np.infty"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0913a68b-7b61-4751-aa45-4b8c2224c625",
   "metadata": {},
   "source": [
    "## python列表可以存不同类型的数据在其中 numpy不行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "060f8952-66bc-4ae8-a696-ac1a5e79b597",
   "metadata": {},
   "outputs": [],
   "source": [
    "a = [1,2.,'3']"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8b4b4699-7dfd-4618-a191-e18975ef213f",
   "metadata": {},
   "source": [
    "## 怎么样创建Numpy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "8ca9f998-8083-4cb2-9940-ef504d8c8f2e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'numpy.ndarray'>\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "\n",
    "a = [1,2,3,4]\n",
    "b = np.array(a)\n",
    "print(type(b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "d0c5a8f9-0138-46ac-9b7e-2bcf07a9a6ab",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(4,)"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "db710984-bf3d-4640-9bee-b38e41624302",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "c30d9d5f-f09f-4a95-ab2e-23c6796ceba7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'numpy.ndarray'>\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "\n",
    "a = [ [1,2,3,4],[5,6,7,8] ]\n",
    "b = np.array(a)\n",
    "print(type(b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "5c2df37e-2c7f-4f2e-9b58-80c78e483a94",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(2, 4)"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "39bc542c-d563-4e0f-9cdd-dff363308f48",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 2, 3, 4],\n",
       "       [5, 6, 7, 8]])"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "9524bd9c-32b0-4e4b-a084-b582911cf8c2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "7"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b[1,2]   #从0开始 第1个列表 第2个数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "f0c2c7c1-7ccd-4042-bb1e-d8a6c64263fa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  1,  2,  3],\n",
       "       [ 4,  5,  6,  7],\n",
       "       [ 8,  9, 10, 11],\n",
       "       [12, 13, 14, 15]])"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.arange(16)\n",
    "a = a.reshape(4,4)\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "d5c82018-ac0f-4b11-97df-1e479490dad5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[[ 0,  1,  2,  3],\n",
       "        [ 4,  5,  6,  7],\n",
       "        [ 8,  9, 10, 11],\n",
       "        [12, 13, 14, 15]],\n",
       "\n",
       "       [[16, 17, 18, 19],\n",
       "        [20, 21, 22, 23],\n",
       "        [24, 25, 26, 27],\n",
       "        [28, 29, 30, 31]],\n",
       "\n",
       "       [[32, 33, 34, 35],\n",
       "        [36, 37, 38, 39],\n",
       "        [40, 41, 42, 43],\n",
       "        [44, 45, 46, 47]],\n",
       "\n",
       "       [[48, 49, 50, 51],\n",
       "        [52, 53, 54, 55],\n",
       "        [56, 57, 58, 59],\n",
       "        [60, 61, 62, 63]]])"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.arange(64)\n",
    "a = a.reshape(4,4,4)\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "2fe1fbbd-086f-4584-8328-edb14c2c3ffa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "38"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a [2,1,2]   #三维  第2排数据 第1行 第2列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "35635f77-86f6-4a53-9543-098a67980b46",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[[ 0,  1],\n",
       "        [ 2,  3]],\n",
       "\n",
       "       [[ 4,  5],\n",
       "        [ 6,  7]],\n",
       "\n",
       "       [[ 8,  9],\n",
       "        [10, 11]],\n",
       "\n",
       "       [[12, 13],\n",
       "        [14, 15]],\n",
       "\n",
       "       [[16, 17],\n",
       "        [18, 19]],\n",
       "\n",
       "       [[20, 21],\n",
       "        [22, 23]],\n",
       "\n",
       "       [[24, 25],\n",
       "        [26, 27]],\n",
       "\n",
       "       [[28, 29],\n",
       "        [30, 31]],\n",
       "\n",
       "       [[32, 33],\n",
       "        [34, 35]],\n",
       "\n",
       "       [[36, 37],\n",
       "        [38, 39]],\n",
       "\n",
       "       [[40, 41],\n",
       "        [42, 43]],\n",
       "\n",
       "       [[44, 45],\n",
       "        [46, 47]],\n",
       "\n",
       "       [[48, 49],\n",
       "        [50, 51]],\n",
       "\n",
       "       [[52, 53],\n",
       "        [54, 55]],\n",
       "\n",
       "       [[56, 57],\n",
       "        [58, 59]],\n",
       "\n",
       "       [[60, 61],\n",
       "        [62, 63]]])"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.arange(64)\n",
    "a = a.reshape(16,2,2)\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "dabaf81b-c1d8-4cff-96ca-e1bbba5229c5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,\n",
       "       27, 28, 29, 30, 31, 32, 33, 34])"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.arange(64)\n",
    "a[10:35]         #切片 左闭右开 从0开始"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "585b5d94-a9a3-4832-a33d-7bbd750f96f5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[25, 26],\n",
       "       [29, 30],\n",
       "       [33, 34],\n",
       "       [37, 38]])"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.arange(64)\n",
    "a = a.reshape(16,4)\n",
    "a[6:10,1:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "544bb5a5-3630-4840-bd67-584a5d950590",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[[  0,   1,   2,   3],\n",
       "        [  4,   5,   6,   7],\n",
       "        [  8,   9,  10,  11],\n",
       "        [ 12,  13,  14,  15],\n",
       "        [ 16,  17,  18,  19],\n",
       "        [ 20,  21,  22,  23],\n",
       "        [ 24,  25,  26,  27],\n",
       "        [ 28,  29,  30,  31],\n",
       "        [ 32,  33,  34,  35],\n",
       "        [ 36,  37,  38,  39],\n",
       "        [ 40,  41,  42,  43],\n",
       "        [ 44,  45,  46,  47],\n",
       "        [ 48,  49,  50,  51],\n",
       "        [ 52,  53,  54,  55],\n",
       "        [ 56,  57,  58,  59],\n",
       "        [ 60,  61,  62,  63]],\n",
       "\n",
       "       [[ 64,  65,  66,  67],\n",
       "        [ 68,  69,  70,  71],\n",
       "        [ 72,  73,  74,  75],\n",
       "        [ 76,  77,  78,  79],\n",
       "        [ 80,  81,  82,  83],\n",
       "        [ 84,  85,  86,  87],\n",
       "        [ 88,  89,  90,  91],\n",
       "        [ 92,  93,  94,  95],\n",
       "        [ 96,  97,  98,  99],\n",
       "        [100, 101, 102, 103],\n",
       "        [104, 105, 106, 107],\n",
       "        [108, 109, 110, 111],\n",
       "        [112, 113, 114, 115],\n",
       "        [116, 117, 118, 119],\n",
       "        [120, 121, 122, 123],\n",
       "        [124, 125, 126, 127]],\n",
       "\n",
       "       [[128, 129, 130, 131],\n",
       "        [132, 133, 134, 135],\n",
       "        [136, 137, 138, 139],\n",
       "        [140, 141, 142, 143],\n",
       "        [144, 145, 146, 147],\n",
       "        [148, 149, 150, 151],\n",
       "        [152, 153, 154, 155],\n",
       "        [156, 157, 158, 159],\n",
       "        [160, 161, 162, 163],\n",
       "        [164, 165, 166, 167],\n",
       "        [168, 169, 170, 171],\n",
       "        [172, 173, 174, 175],\n",
       "        [176, 177, 178, 179],\n",
       "        [180, 181, 182, 183],\n",
       "        [184, 185, 186, 187],\n",
       "        [188, 189, 190, 191]],\n",
       "\n",
       "       [[192, 193, 194, 195],\n",
       "        [196, 197, 198, 199],\n",
       "        [200, 201, 202, 203],\n",
       "        [204, 205, 206, 207],\n",
       "        [208, 209, 210, 211],\n",
       "        [212, 213, 214, 215],\n",
       "        [216, 217, 218, 219],\n",
       "        [220, 221, 222, 223],\n",
       "        [224, 225, 226, 227],\n",
       "        [228, 229, 230, 231],\n",
       "        [232, 233, 234, 235],\n",
       "        [236, 237, 238, 239],\n",
       "        [240, 241, 242, 243],\n",
       "        [244, 245, 246, 247],\n",
       "        [248, 249, 250, 251],\n",
       "        [252, 253, 254, 255]]])"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.arange(256)\n",
    "a = a.reshape(4,16,4)\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a61f1cd2-343f-4cea-8e8c-8045fca529e1",
   "metadata": {},
   "outputs": [],
   "source": [
    "a = np.arange(256)\n",
    "a = a.reshape(4,16,4)\n",
    "a["
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dc814d81-948d-4504-87ca-f085512a7137",
   "metadata": {},
   "source": [
    "NumPy支持的数据类型如下：\n",
    "\n",
    "| 类型        | 代码   |  说明|\n",
    "|:------------|:------|:------|\n",
    "|int8、uint8   |i1、u1 |有符号和无符号整型（1字节） |\n",
    "|int16、uint16 |i2、u2 |有符号和无符号整型（2字节） |\n",
    "|int32、uint32 |i4、u4 |有符号和无符号整型（4字节） |\n",
    "|int64、uint64 |i8、u8 |有符号和无符号整型（8字节） |\n",
    "|float16       |f2     |半精度浮点数 |\n",
    "|float32       |f4、f  |单精度浮点数 |\n",
    "|float64       |f8、d  |双精度浮点数 |\n",
    "|float128      |f16、g |扩展精度浮点数  |\n",
    "|complex64     |c8     |分别用两个32位表示的复数 |\n",
    "|complex128    |c16    |分别用两个64位表示的复数 |\n",
    "|complex256    |c32    |分别用两个128位表示的复数 |\n",
    "|`bool_`      |?      |布尔型  |\n",
    "|`object_`      |O      |python对象  |\n",
    "|`str_`        |Sn     |固定长度字符串，每个字符1字节，如S8  |\n",
    "|`unicode`     |Un     |固定长度Unicode，字节数由系统决定，如U8 |\n",
    "|`datetime64`   |     |日期|\n",
    "|`timedelta64`   |     |日期差|"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "71298e1c-9878-4639-a2b7-9fce102b9f72",
   "metadata": {},
   "source": [
    "# 画点"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "5b5caf33-a4a2-46f6-887e-97e96812b945",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/jpeg": "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQgJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAEsASwDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD5/ooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigA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AUUUUAFFFFABRRRQB/9k=",
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAASwAAAEsCAIAAAD2HxkiAAAEuElEQVR4Ae3QQREAAAzCMPybZjLGI1XQSyICBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQ2BRoN79cESBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIfAsclC0B/7LmiWQAAAAASUVORK5CYII=",
      "text/plain": [
       "<PIL.Image.Image image mode=RGB size=300x300>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "from PIL import Image\n",
    "\n",
    "\n",
    "#im = np.random.randint(0,255, (100,300,3), dtype=np.uint8)\n",
    "def dot(x,y,color):\n",
    "    im[x,y] = color\n",
    "\n",
    "im = np.zeros((300,300,3),dtype=np.uint8)\n",
    "\n",
    "im[150,150]=(0,255,255)                     #在画布[]位置上 画一个色为()的像素点    ()三原色rgb\n",
    "im = Image.fromarray(im)\n",
    "\n",
    "display(im)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "ea9c8cb9-35ff-4c9f-bfd4-df2d32466d36",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/jpeg": "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQgJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAEsASwDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD5/ooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigCe1tJLyUxxNCrBd2Zp0iGPq5Azz0qCiilrcWtwooopjCiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooA//2Q==",
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAASwAAAEsCAIAAAD2HxkiAAAEvUlEQVR4Ae3RsQEAAAQEMfYfmuqXIJqvL6ocAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQI3Bfpm1p+qSapPRsISIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAhEYAF77QECO+PfCgAAAABJRU5ErkJggg==",
      "text/plain": [
       "<PIL.Image.Image image mode=RGB size=300x300>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "from PIL import Image\n",
    "\n",
    "\n",
    "#im = np.random.randint(0,255, (100,300,3), dtype=np.uint8)\n",
    "def dot(x,y,color):\n",
    "    im[x,y] = color\n",
    "\n",
    "im = np.zeros((300,300,3),dtype=np.uint8)\n",
    "\n",
    "dot(150,150,(0,255,0))  #在画布[]位置上 画一个色为()的像素点    ()三原色rgb\n",
    "dot(150,151,(0,255,0))    \n",
    "dot(150,149,(0,255,0))    \n",
    "\n",
    "im = Image.fromarray(im)\n",
    "\n",
    "display(im)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d6d986b8-ad82-4b62-ab51-0f66ce9c9487",
   "metadata": {},
   "source": [
    "# 画线"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0bd7ae6d-00c1-4826-8abb-58dbe672cb55",
   "metadata": {},
   "source": [
    "#### 彩色"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "72629d47-ff95-46e0-84bf-60e3bc8d9140",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/jpeg": "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQgJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAGQAZADASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD5/ooqeONJ4wiDE46D/np7f73t3+vVN2LhBzdlv+f9f1qQUUUUyAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigCz/AMfv/X1/6N/+y/n9fvVqKs/8fv8A19f+jf8A7L+f1+9Hw+h0fxv8X5/8H8/XetRRRVnOFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAWf8Aj9/6+v8A0b/9l/P6/erUVZ/4/f8Ar6/9G/8A2X8/r96Ph9Do/jf4vz/4P5+u9aiiirOcKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAs/8AH7/19f8Ao3/7L+f1+9Woqz/x+/8AX1/6N/8Asv5/X70fD6HR/G/xfn/wfz9d61FFFWc4UUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQBZ/4/f+vr/wBG/wD2X8/r96tRVn/j9/6+v/Rv/wBl/P6/ej4fQ6P43+L8/wDg/n671qKKKs5wooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigCz/x+/wDX1/6N/wDsv5/X71airP8Ax+/9fX/o3/7L+f1+9Hw+h0fxv8X5/wDB/P13rUUUVZzhRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFAFn/j9/wCvr/0b/wDZfz+v3q1FWf8Aj9/6+v8A0b/9l/P6/ej4fQ6P43+L8/8Ag/n671qKKKs5wooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigCz/x+/8AX1/6N/8Asv5/X71airP/AB+/9fX/AKN/+y/n9fvR8PodH8b/ABfn/wAH8/XetRRRVnOFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAWf+P3/r6/9G//AGX8/r96tRVn/j9/6+v/AEb/APZfz+v3o+H0Oj+N/i/P/g/n671qKKKs5wooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigCz/AMfv/X1/6N/+y/n9fvVqKs/8fv8A19f+jf8A7L+f1+9Hw+h0fxv8X5/8H8/XetRRRVnOFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAWf8Aj9/6+v8A0b/9l/P6/erUVZ/4/f8Ar6/9G/8A2X8/r96Ph9Do/jf4vz/4P5+u9aiiirOcKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAs/8AH7/19f8Ao3/7L+f1+9Woqz/x+/8AX1/6N/8Asv5/X70fD6HR/G/xfn/wfz9d61FFFWc4UUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQBZ/4/f+vr/wBG/wD2X8/r96tRVn/j9/6+v/Rv/wBl/P6/ej4fQ6P43+L8/wDg/n671qKKKs5wooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigCz/x+/wDX1/6N/wDsv5/X71airP8Ax+/9fX/o3/7L+f1+9Hw+h0fxv8X5/wDB/P13rUUUVZzhRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFAFn/j9/wCvr/0b/wDZfz+v3q1FWf8Aj9/6+v8A0b/9l/P6/ej4fQ6P43+L8/8Ag/n671qKKKs5wooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigCz/x+/8AX1/6N/8Asv5/X71airP/AB+/9fX/AKN/+y/n9fvR8PodH8b/ABfn/wAH8/XetRRRVnOFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAWf+P3/r6/9G//AGX8/r96tRVn/j9/6+v/AEb/APZfz+v3o+H0Oj+N/i/P/g/n671qKKKs5wooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigCz/AMfv/X1/6N/+y/n9fvVqKs/8fv8A19f+jf8A7L+f1+9Hw+h0fxv8X5/8H8/XetRRRVnOFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFF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BAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQOBN4AAc9CHtoOP/egAAAABJRU5ErkJggg==",
      "text/plain": [
       "<PIL.Image.Image image mode=RGB size=400x400>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "from PIL import Image\n",
    "\n",
    "# im = np.random.randint(0,255, (100,300,3), dtype=np.uint8)\n",
    "def dot(x, y, color=(255,0,0) ):\n",
    "    im[x, y] = color\n",
    "\n",
    "def line(x1, y1, x2, y2, color):\n",
    "    for x in range(x1, x2+1):\n",
    "        y = int((x-x1)/(x2-x1)*(y2-y1)+0.5)+ y1  #必须是整数 所以int\n",
    "        dot(x,y,color)\n",
    "    \n",
    "im = np.zeros( (400,400,3), dtype=np.uint8) \n",
    "\n",
    "line(10,10,300,300,(255,0,0))\n",
    "\n",
    "im = Image.fromarray(im)\n",
    "\n",
    "display(im)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "eccbcdc5-9ac4-4180-b0b5-dc0e2d62fa61",
   "metadata": {},
   "source": [
    "#### 灰度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "e0bdb4a8-0952-4c3f-93a6-050c8052b977",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/jpeg": "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQgJCQ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1cOBNMoBW6XB+d+ciUHAJGd+cnDBmkAMuiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKAP/Z",
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZAAAAGQCAIAAAAP3aGbAAAL20lEQVR4Ae3UwQ0AQQgDse2/aa6Ke4xiKggG5T1DgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgRCAncXSisqAQLrAjpr/QPsT6AloLNa95KWwLqAzlr/APsTaAnorNa9pCWwLqCz1j/A/gRaAjqrdS9pCawL6Kz1D7A/gZaAzmrdS1oC6wI6a/0D7E+gJaCzWveSlsC6gM5a/wD7E2gJ6KzWvaQlsC6gs9Y/wP4EWgI6q3UvaQmsC+is9Q+wP4GWgM5q3UtaAusCOmv9A+xPoCWgs1r3kpbAuoDOW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gQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECPwl8RxdlxRn0eycAAAAASUVORK5CYII=",
      "text/plain": [
       "<PIL.Image.Image image mode=RGB size=400x400>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "from PIL import Image\n",
    "\n",
    "# im = np.random.randint(0,255, (100,300,3), dtype=np.uint8)\n",
    "def dot(x, y, color=(255,0,0) ):\n",
    "    im[x, y] = color\n",
    "\n",
    "def line(x1, y1, x2, y2, color):\n",
    "    for x in range(x1, x2+1):\n",
    "        y = int((x-x1)/(x2-x1)*(y2-y1)+0.5)+ y1  #必须是整数 所以int\n",
    "        dot(x,y,color)\n",
    "    \n",
    "im = np.zeros( (400,400,3), dtype=np.uint8) \n",
    "\n",
    "line(10,10,300,300,255)\n",
    "\n",
    "im = Image.fromarray(im)\n",
    "\n",
    "display(im)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e592c5c0-d535-4eab-a11e-d78f6b1fc60f",
   "metadata": {},
   "source": [
    "## 写出一个可以画出任何线的代码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "10fe342d-3ec4-4797-9182-f4ef3a34dea4",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from PIL import Image\n",
    "\n",
    "def dot(x, y, im, color=(255,0,0)):\n",
    "    if 0 <= x < im.shape[1] and 0 <= y < im.shape[0]:\n",
    "        im[y, x] = color\n",
    "\n",
    "def line(x0, y0, x1, y1, im, color):\n",
    "    dx = abs(x1 - x0)\n",
    "    dy = abs(y1 - y0)\n",
    "    sx = 1 if x0 < x1 else -1\n",
    "    sy = 1 if y0 < y1 else -1\n",
    "    err = dx - dy\n",
    "    \n",
    "    while True:\n",
    "        dot(x0, y0, im, color)\n",
    "        if x0 == x1 and y0 == y1:\n",
    "            break\n",
    "        e2 = 2 * err\n",
    "        if e2 > -dy:\n",
    "            err -= dy\n",
    "            x0 += sx\n",
    "        if e2 < dx:\n",
    "            err += dx\n",
    "            y0 += sy\n",
    "\n",
    "def display(im):\n",
    "    im = Image.fromarray(im)\n",
    "    im.show()\n",
    "\n",
    "\n",
    "im = np.zeros((400, 400, 3), dtype=np.uint8)\n",
    "\n",
    "line(10, 10, 300, 300, im, (255, 0, 0))\n",
    "\n",
    "display(im)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d54cb232-5688-4fdf-ba95-e52395fc81e4",
   "metadata": {},
   "source": [
    "## 写出一个可以画圆的函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e3652667-226c-4f77-9124-2ab05703a455",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from PIL import Image\n",
    "\n",
    "# im = np.random.randint(0,255, (100,300,3), dtype=np.uint8)\n",
    "def dot(x, y, im, color=(255, 0, 0)):\n",
    "    im[y, x] = color\n",
    "\n",
    "def line(x1, y1, x2, y2, im, color):\n",
    "    for x in range(x1, x2 + 1):\n",
    "        y = int((x - x1) / (x2 - x1) * (y2 - y1) + 0.5) + y1  #必须是整数 所以int\n",
    "        dot(x, y, im, color)\n",
    "\n",
    "def circle(im, cx, cy, r, color):\n",
    "    x = 0\n",
    "    y = r\n",
    "    d = 3 - 2 * r\n",
    "    while x <= y:\n",
    "        for i in range(x - y + 1):\n",
    "            dot(i + cx, x + cy, im, color)\n",
    "            dot(-i + cx, x + cy, im, color)\n",
    "            dot(-x + cx, i + cy, im, color)\n",
    "            dot(x + cx, i + cy, im, color)\n",
    "        if d < 0:\n",
    "            d += 4 * x + 6\n",
    "        else:\n",
    "            d += 4 * (x - y) + 10\n",
    "            y -= 1\n",
    "        x += 1\n",
    "\n",
    "def display(im):\n",
    "    im = Image.fromarray(im)\n",
    "    im.show()\n",
    "    \n",
    "im = np.zeros((400, 400, 3), dtype=np.uint8)\n",
    "\n",
    "line(10, 10, 300, 300, im, (255, 0, 0))\n",
    "\n",
    "circle(im, 300, 300, 100, (0, 255, 0))\n",
    "\n",
    "display(im)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "56ff1de6-fbba-4997-a9c6-4d265c3d29eb",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from PIL import Image\n",
    "\n",
    "# im = np.random.randint(0,255, (100,300,3), dtype=np.uint8)\n",
    "def dot(x, y, color=(255,0,0) ):\n",
    "    im[x, y] = color\n",
    "\n",
    "def line(x1, y1, x2, y2, color):\n",
    "    for x in range(x1, x2+1):\n",
    "        y = int((x-x1)/(x2-x1)*(y2-y1)+0.5)+ y1  #必须是整数 所以int\n",
    "        dot(x,y,color)\n",
    "\n",
    "def circle(x,y,r,color):\n",
    "    pass\n",
    "\n",
    "    \n",
    "im = np.zeros( (400,400,3), dtype=np.uint8) \n",
    "\n",
    "line(10,10,300,300,(255,0,0))\n",
    "\n",
    "im = Image.fromarray(im)\n",
    "\n",
    "display(im)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
